package entity;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;    
import java.io.IOException;
import org.jfree.chart.ChartFactory;    
import org.jfree.chart.JFreeChart;  
import org.jfree.chart.plot.PiePlot3D;  
import org.jfree.data.general.DefaultPieDataset;  
import org.jfree.util.Rotation;  
  
public class PieChartExample {   
	
	public static JFreeChart CreatePieChart(String str1,double i,String str2,double j) throws IOException{
		//获得数据集
		DefaultPieDataset df=new DefaultPieDataset();
		df.setValue(str1, i);
		df.setValue(str2, j);
		//创建3D饼图  
        JFreeChart chart = ChartFactory.createPieChart3D("统计结果饼状图",df, true, true, false);
        //设置图片背景色  
        chart.setBackgroundPaint(Color.white);
        //取得3D饼图对象  
        PiePlot3D plot = (PiePlot3D) chart.getPlot();  
        //指定显示的饼图上圆形(false)还椭圆形(true)  
        plot.setCircular(false); 
        //设置图形边框颜色  
        //plot.setBaseSectionOutlinePaint(Color.red);   
        // 图形边框粗细  
        plot.setBaseSectionOutlineStroke(new BasicStroke(0.7f));
        //设置旋转角度  
        plot.setStartAngle(290);
        //设置旋转方向  
        plot.setDirection(Rotation.CLOCKWISE);  
        //设置透明度  
        plot.setForegroundAlpha(0.9f);
        //设置标题字体 
        chart.getTitle().setFont(new Font("幼圆",Font.BOLD,25));
        chart.getLegend().setItemFont(new Font("幼圆",Font.BOLD,20));
        plot.setLabelFont((new Font("幼圆", Font.PLAIN, 20))); 
        
        return chart;
        
      /*  FileOutputStream fos_jpg = null; 
        try { 
            fos_jpg = new FileOutputStream("D:\\pie.jpg"); 
            ChartUtilities.writeChartAsJPEG(fos_jpg, 1, chart, 400, 300);
            //ChartUtilities.writeChartAsJPEG(fos_jpg,100,chart,400,300,null); 
        } finally { 
            try { 
                fos_jpg.close(); 
            } catch (Exception e) {} 
        }*/
	}
	

}
 